﻿using System.Globalization;
using System.Threading;
using System.Web.Mvc;

namespace CRM.Controllers
{
    /// <summary>
    /// Определяет ресурсы какого языка подгружать
    /// </summary>
    public class LocalizeAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string culture;
            if (filterContext.HttpContext.Session["Culture"] != null)
            {
                culture = filterContext.HttpContext.Session["Culture"].ToString();
            }
            else
            {
                culture = "ru-RU";
            }

           

            CultureInfo cultureInfo = new CultureInfo(culture);
            Thread.CurrentThread.CurrentCulture = cultureInfo;
            Thread.CurrentThread.CurrentUICulture = cultureInfo;

            base.OnActionExecuting(filterContext);
        }
    }
}